#!/bin/sh /etc/rc.common
START=50

run_poweroff()
{
	local enable
	config_get_bool enable $1 enable

	if [ $enable = 1 ]; then
		local minute
		local hour
		config_get week $1 week
		config_get minute $1 minute
		config_get hour $1 hour
    if [ $minute = 0 ] ; then
        minute="00"
		fi
    if [ $week = 7 ] ; then
        week="*"
		fi
		sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 &
		/etc/init.d/cron restart
		echo "$minute $hour * * $week sleep 5 && touch /etc/banner && poweroff" >> /etc/crontabs/root
		/etc/init.d/cron restart
		echo "Auto poweroff has started."
	else
		sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 &
		/etc/init.d/cron restart
		echo "Auto REBOOT has started."
	fi
}

start()
{
	config_load autopoweroff
	config_foreach run_poweroff login
}

stop()
{
	echo "Auto poweroff has stoped."
}
